<template>
  <div class="app-container" style="width:100%;">
    <el-form ref="form" :model="form" label-width="100px">
      <el-form-item label="模板code">
        <el-input v-model="form.code" style="width:100%;" disabled />
      </el-form-item>
      <el-form-item label="模板名称">
        <el-input v-model="form.name" style="width:100%;" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.remark" type="textarea" :autosize="{ minRows: 2, maxRows: 2}" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <div style="text-align:center;">
        <el-button type="primary" @click="onSave">保存</el-button>
        <el-button type="danger" class="quxiao_btn" @click="closePage()">取消</el-button>
      </div>
    </span>
  </div>
</template>

<script>
import { copyData } from '@/api/catalogManage'

import { Message } from 'element-ui'

export default {
  name: 'Zzjg',
  inject: ['getList'],
  props: { // 第二种方式
    proid: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      form: {
        code: 'PROJECT_CATALOG'
      }
    }
  },
  created() {
  },
  methods: {
    onSave() {
      if (this.form.name === '' || this.form.name === 'null' || this.form.name === undefined) {
        Message({
          message: '模板名称不能为空',
          type: 'error',
          duration: 5 * 1000
        })
        return
      }
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })

      var submitData = {}
      submitData.data = this.form
      submitData.data1 = this.proid
      copyData(submitData).then(response => {
        Message({
          message: '复制成功',
          type: 'success',
          duration: 5 * 1000
        })

        loading.close()
        this.$emit('update:visible', false)
        // 重新加载表格
        this.getList()
      }).catch(response => {
        loading.close()
        // 重新加载表格
        this.getList()
      })
    },
    closePage() {
      this.$emit('update:visible', false)
      this.getList()
    }
  }
}
</script>

<style scoped>

</style>
